/*
 * log.h
 *
 *  Created on: Dec 13, 2014
 *      Author: YangBo
 *
 */

#ifndef PLCC_LOG_LOG_H_
#define PLCC_LOG_LOG_H_

#define MAX_FLUSH_NUM 10

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <ctime>
#include <stdlib.h>
#include <stdio.h>
#include <iomanip>
#include "pthread.h"
#include "../thread/Mutex.h"
#include "Log_Def.h"
using namespace std;


enum ENUM_LOG_LEVEL {
  LOG_LEVEL_DEBUG,
  LOG_LEVEL_INFO,
  LOG_LEVEL_WARNING,
  LOG_LEVEL_ERROR,
  LOG_LEVEL_END
};


static const char LogLevelName[4][20] =
{
  "[DEBUG  -] ",
  "[INFO   -] ",
  "[WARNING-] ",
  "[ERROR  -] "
};

class Logger {
 public:
  Logger();
  Logger(ENUM_LOG_LEVEL level);
  ~Logger();
  bool OpenFile();
  bool CloseFile();
  virtual void LogConfig()=0;
  bool SetLevel(ENUM_LOG_LEVEL newlevel);
  bool IfRotateLog();
  bool RotateLog();
  string GetSystemTime();
  bool log(string& msg);

 protected:
  ENUM_LOG_LEVEL loglevel;
  int flush_num;
  string filename;
  tm oldtime;
  string filepath;
 	fstream file;
  
};


class SettingLogger: public Logger {
 public:
  SettingLogger();
  ~SettingLogger();
  virtual void LogConfig();

};

class PlayingLogger: public Logger {
 public:
  PlayingLogger();
  ~PlayingLogger();
  virtual void LogConfig();

};

class NettingLogger: public Logger {
 public:
  NettingLogger();
  ~NettingLogger();
  virtual void LogConfig();

};

struct LogType {
 ENUM_LOG_LEVEL level;
 string msg; 
};


#endif
